#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
import tornadio 

from bisnesslogic import Main

class ClientConnection(tornadio.SocketConnection, Main):
    def __init__(self, *args, **kwargs):
        logging.warning('ClientConnection::__init__ start')
        
        Main.__init__(self)
        tornadio.SocketConnection.__init__(self, *args, **kwargs)
        #self.coordinator = Coordinator()
        
        logging.warning('ClientConnection::__init__ finish')
        
    def on_open(self, *args, **kwargs):
        logging.warning('ClientConnection::on_open start')
        
        self.on_request('connect')
        
        logging.warning('ClientConnection::on_open finish')
        
    def on_message(self, message):
        logging.warning('ClientConnection::on_message start')
        logging.warning(message)
        
        self.on_request(message)
        
        logging.warning('ClientConnection::on_message finish')
        
    def on_close(self):
        logging.warning('ClientConnection::on_close start')

        self.on_request('disconnect')
        
        logging.warning('ClientConnection::on_close finish')
        
    def on_response(self, message):
        self.send(message);